package com.lvcoding.sec3.secdemo3.validatecode.sms;

import com.lvcoding.sec3.secdemo3.validatecode.parent.AbstraceValidateCodeProcessor;
import com.lvcoding.sec3.secdemo3.validatecode.parent.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

@Component
public class SmsCodeProcessor extends AbstraceValidateCodeProcessor<SmsCode> {

    @Autowired
    private SmsCodeSender smsCodeSender;


    @Override
    protected void send(ServletWebRequest request, SmsCode validateCode) throws Exception {
        String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), "mobile");
        smsCodeSender.send(mobile, validateCode.getCode());
    }
}
